* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #3498db;
    --text-color: #333;
    --bg-color: #f5f5f5;
    --container-bg: rgba(255, 255, 255, 0.95);
    --content-bg: #fafafa;
}

html {
    font-size: 16px;
}

body {
    font-family: 'Microsoft YaHei', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    background-image: linear-gradient(to bottom right, #f3e7e9, #e3eeff);
    min-height: 100vh;
    padding: 1rem;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.5rem;
    background-color: var(--container-bg);
    border-radius: 10px;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
}

h1 {
    text-align: center;
    color: #2c3e50;
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.controls {
    text-align: center;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0 1rem;
}

button {
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 80px;
}

button:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
}

button:disabled {
    background-color: #bdc3c7;
    cursor: not-allowed;
    transform: none;
}

select {
    width: 100%;
    max-width: 300px;
    padding: 0.6rem;
    font-size: 0.9rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    background-color: white;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: #3498db;
}

@media screen and (min-height: 600px) {
    select {
        max-height: 200px;
    }
}

@media screen and (max-height: 600px) {
    select {
        max-height: 180px;
    }
}

@media screen and (max-width: 768px) {
    select {
        width: 100%;
        max-width: none;
        margin: 0.5rem 0;
        font-size: 16px;
        padding: 0.8rem;
    }
}

@media screen and (max-width: 375px) {
    select {
        max-height: 160px;
    }
}

/* 移动端优化 */
@media screen and (max-width: 768px) {
    .controls {
        position: relative;
        z-index: 100;
    }
}

/* 内容区域样式 */
.story-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    padding-bottom: 64px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.03);
}

.story-content {
    font-size: 1.1rem;
    line-height: 1.8;
    color: #333;
    letter-spacing: 0.5px;
    text-align: justify;
}

.story-content p {
    margin-bottom: 1.2em;
}

h2 {
    font-size: 1.5rem;
    color: #2c3e50;
    margin-bottom: 1.5rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid #eee;
}

@media (max-width: 768px) {
    .story-container {
        padding: 16px;
        padding-bottom: 64px;
        border-radius: 0;
        box-shadow: none;
    }

    .story-content {
        font-size: 1.05rem;
        line-height: 1.75;
        letter-spacing: 0.3px;
    }

    h2 {
        font-size: 1.3rem;
        margin-bottom: 1.2rem;
        padding-bottom: 0.6rem;
    }
}

/* 移动端适配 */
@media screen and (max-width: 768px) {
    html {
        font-size: 14px;
    }

    body {
        padding: 0.5rem;
    }

    .container {
        padding: 1rem;
        padding-bottom: calc(2rem + 44px);
    }

    .controls {
        gap: 0.5rem;
        padding: 0;
    }

    button {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        flex: 1;
        min-width: 60px;
    }

    .story-container {
        padding: 1rem;
        padding-bottom: 50px;
    }

    .story-content {
        padding: 0.8rem;
        font-size: 1rem;
        line-height: 1.6;
        padding-bottom: 0;
        margin-bottom: 0;
    }
}

/* 小屏幕手机适配 */
@media screen and (max-width: 375px) {
    html {
        font-size: 13px;
    }

    .container {
        padding: 0.8rem;
    }

    .controls {
        flex-direction: column;
    }

    button, select {
        width: 100%;
        margin: 0.3rem 0;
    }

    .story-content {
        padding: 0.6rem;
    }
}

.custom-select {
    position: relative;
    width: 100%;
    max-width: 300px;
    background: white;
    border-radius: 5px;
    cursor: pointer;
}

.select-header {
    padding: 0.6rem 1rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
}

.select-header:hover {
    border-color: #3498db;
}

/* 移动端标题栏默认隐藏 */
.mobile-select-header {
    display: none;
}

/* PC端下拉菜单样式 */
@media screen and (min-width: 769px) {
    .select-options {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: white;
        border: 1px solid #ddd;
        border-top: none;
        border-radius: 0 0 5px 5px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        max-height: 300px;
        overflow-y: auto;
        z-index: 1000;
    }
    .mobile-select-header {
        display: none;
    }
    .select-option {
        padding: 0.6rem 1rem;
        border-bottom: 1px solid #eee;
    }

    .select-option:hover {
        background-color: #f5f5f5;
    }

    .select-option.selected {
        background-color: #e8f4fc;
        color: #3498db;
    }
}

/* 移动端下拉菜单样式 */
@media screen and (max-width: 768px) {
    .custom-select {
        max-width: none;
        margin: 0.5rem 0;
    }

    .select-options {
        display: none;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        background: white;
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        z-index: 1000;
        max-height: 70vh;
        overflow-y: auto;
    }

    .mobile-select-header {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        padding: 12px 16px;
        border-bottom: 1px solid #eee;
        position: sticky;
        top: 0;
        background: white;
        z-index: 2;
    }

    .mobile-select-title {
        font-size: 16px;
        font-weight: 500;
        color: #333;
        flex: 1;
        text-align: center;
        margin-right: 56px; /* 与关闭按钮宽度相同，保持标题居中 */
    }

    .mobile-select-close {
        border: none;
        background: none;
        padding: 8px 16px;
        color: #666;
        font-size: 15px;
        cursor: pointer;
        -webkit-appearance: none;
        appearance: none;
        border-radius: 4px;
        transition: background-color 0.2s;
    }

    .mobile-select-close:active {
        background-color: #f0f0f0;
    }

    .select-option {
        padding: 0.8rem 1rem;
        border-bottom: 1px solid #eee;
    }

    .select-option:last-child {
        border-bottom: none;
    }

    .select-option:active {
        background-color: #f0f0f0;
    }

    .select-option.selected {
        color: #3498db;
        font-weight: 500;
    }

    .chapter-list {
        padding: 8px 0;
        padding-bottom: max(env(safe-area-inset-bottom), 20px);
    }
}

.custom-select.open .select-options {
    display: block;
}

.select-options-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #eee;
    position: sticky;
    top: 0;
    background: white;
    z-index: 2;
}

.select-options-header span {
    font-weight: 500;
    font-size: 1.1rem;
}

.close-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: none;
    color: #666;
    cursor: pointer;
    font-size: 0.9rem;
}

.close-btn:active {
    color: #333;
}

.chapter-list {
    padding-bottom: env(safe-area-inset-bottom);
}

/* 移动端优化 */
@media screen and (max-width: 768px) {
    .select-options {
        padding-top: 0;
    }
    
    .select-options-header {
        padding: 1rem;
        background: #f8f8f8;
    }
    
    .chapter-list {
        padding-bottom: max(env(safe-area-inset-bottom), 20px);
    }
}

/* 移动端遮罩层 */
@media screen and (max-width: 768px) {
    .custom-select.open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.3);
        z-index: 999;
    }

    .select-options {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        background: white;
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        z-index: 1000;
        max-height: 70vh;
        overflow-y: auto;
        display: none;
    }

    .custom-select.open .select-options {
        display: block;
    }
}

.bottom-controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 56px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    display: none;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
}

.bottom-controls button {
    min-width: 90px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: #f0f0f0;
    font-size: 14px;
    color: #333;
    padding: 0 16px;
    transition: all 0.2s;
}

.bottom-controls button:active {
    background: #e5e5e5;
    transform: scale(0.98);
}

.bottom-controls button:disabled {
    opacity: 0.5;
    background: #f0f0f0;
}

@media (max-width: 768px) {
    .bottom-controls {
        gap: 16px;
    }
    
    .bottom-controls button {
        width: 100px;
    }
}
